package com.license.logic.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.license.common.util.DbConnection;
import com.license.logic.preference.Activity;

public class ActivityDao {
	private Connection connection ;
	
	public ActivityDao(){
		this.connection = DbConnection.getCon();
	}
	public  Map<String, Activity> getAllActivities(){
		 Map<String, Activity> activitiesMap = new HashMap<String, Activity>();
		 Statement stmt;
	        try {
	            stmt = this.connection.createStatement();
	            ResultSet rs;
	            rs = stmt.executeQuery("Select * from activities");
	            while ( rs.next()){
	            	Activity activity = new Activity();
	            	activity.setName(rs.getString("exercise"));
	            	activity.setKalories(Integer.parseInt(rs.getString("kalories")));
	            	activity.setKg(Integer.parseInt(rs.getString("grams")));
	            	activity.setMinutes(Integer.parseInt(rs.getString("minutes")));
	            	activitiesMap.put(activity.getName(), activity);
	            }

	        } catch (SQLException e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }
		 return activitiesMap;
	}
	
	public List <String> getAllActivityNames(){
		List <String> activities = new ArrayList<String>();
		 Statement stmt;
	        try {
	            stmt = this.connection.createStatement();
	            ResultSet rs;
	            rs = stmt.executeQuery("Select * from activities");
	            while ( rs.next()){
	            	activities.add(rs.getString("exercise"));
	            }

	        } catch (SQLException e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }
		 return activities;
	}
}
